package spark.core.java;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

/**
 * spark持久化操作
 */
public class Persist {


    public static void main(String[] args) {
        SparkConf conf = new SparkConf().setAppName("LocalFile");
        JavaSparkContext sc = new JavaSparkContext(conf);
        long start = System.currentTimeMillis();
        JavaRDD<String> lines = sc.textFile("datas/wordcount.txt");
        lines.count();
        long end = System.currentTimeMillis();
        System.out.println("use time is " + (end - start));
        start = System.currentTimeMillis();
        lines = sc.textFile("datas/wordcount.txt").cache();
        lines.count();
        end = System.currentTimeMillis();
        System.out.println("after cache,use time is " + (end - start));

    }
}
